package com.gxa.shop.servlet.category;

import com.gxa.shop.bean.pojo.Category;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.gxa.shop.commons.r.R;
import com.gxa.shop.service.category.CategoryService;
import com.gxa.shop.service.category.impl.CategoryServiceImpl;


import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * com.gxa.shop.bean.servlet.category
 * User: zjy
 * Date: 2024/12/17 14:37
 * motto:   逆水行舟不进则退
 * Description:
 * Version: V1.0
 */
@WebServlet(name = "CategoryUpdateServlet",value = "/category/updateById")
public class CategoryUpdateServlet extends HttpServlet {
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        BufferedReader bufferedReader=req.getReader();
        String  req_data=bufferedReader.readLine();
        Category category= JSONObject.parseObject(req_data, Category.class);
        CategoryService categoryService=new CategoryServiceImpl();

        boolean update = categoryService.update(category);
        R r=!update? R.error("修改失败"):R.ok();
        //
        PrintWriter writer = resp.getWriter();
        String  result= JSON.toJSONString(r);
        System.out.println("UpdateCategoryServlet:"+result);
        writer.write(result);
        writer.flush();
        writer.close();
    }
}